﻿<%@ WebHandler Language="C#" Class="SYS_Product_add" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;

public class SYS_Product_add : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }

            string Id = Guid.NewGuid().ToString();
            string StoreId = context.Session["comid"].ToString();
            //string StoreId = "9f1dfd1d-7bf3-479e-8c35-01a59d1ab167";
            string CategoryId = "";
            if (context.Request["CategoryId"] != null)
            {
                CategoryId = context.Request["CategoryId"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递CategoryId参数";
                unit.send(context, result);
                return;
            }
            string BannerId = Guid.NewGuid().ToString();
            string Title = "";
            if (context.Request["Title"] != null)
            {
                Title = context.Request["Title"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递Title参数";
                unit.send(context, result);
                return;
            }
            string SubTitle = "";
            if (context.Request["SubTitle"] != null)
            {
                SubTitle = context.Request["SubTitle"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递SubTitle参数";
                unit.send(context, result);
                return;
            }
            string AveragePrice = "";
            if (context.Request["AveragePrice"] != null)
            {
                AveragePrice = context.Request["AveragePrice"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递AveragePrice参数";
                unit.send(context, result);
                return;
            }
            string Price = "";
            if (context.Request["Price"] != null)
            {
                Price = context.Request["Price"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递Price参数";
                unit.send(context, result);
                return;
            }
            string ActivityPrice = "";
            if (context.Request["ActivityPrice"] != null)
            {
                ActivityPrice = context.Request["ActivityPrice"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递ActivityPrice参数";
                unit.send(context, result);
                return;
            }

            string DetailImgId = Guid.NewGuid().ToString();
            string Cover = Guid.NewGuid().ToString();
            
            string DetailText = "";
            if (context.Request["DetailText"] != null)
            {
                DetailText = context.Request["DetailText"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递Series参数";
                unit.send(context, result);
                return;
            }
            string CreateTime = DateTime.Now.ToString();
            string Enable = "1";

            str = "insert into SYS_Product(Id,StoreId,CategoryId,BannerId,Title,SubTitle,AveragePrice,Price,ActivityPrice,DetailText,Cover,CreateTime,Enable,DetailImgId) values('" + Id + "','" + StoreId + "','" + CategoryId + "','" + BannerId + "','" + Title + "','" + SubTitle + "'," + AveragePrice + "," + Price + "," + ActivityPrice + ",'" + DetailText + "','" + Cover + "','" + CreateTime + "'," + Enable + ",'" + DetailImgId + "')";
            if (sql.ExecuteNonQuery(str) > 0)
            {
                result.code = "1";
                result.msg = "";
            }
            else
            {
                result.code = "0";
                result.msg = "添加失败";
            }

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
        unit.send(context, result);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
